package timbap.visualizer.api.plugin.recorditems;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import timbap.visualizer.api.model.RecordItem;
import timbap.visualizer.api.plugin.AbstractPlugin;

/**
 * The <code>AbstractSelectedRecordItemPlugin</code> provides a specific
 * implementation of the <code>ItemsPlugin</code> interface for
 * plugins which draw only the selected record item.
 *
 * @author  Andreas Pabst
 * @see     timbap.visualizer.api.model.RecordItem
 * @see     timbap.visualizer.api.plugin.recorditems.RecordItemsPlugin
 * @see     timbap.visualizer.api.plugin.AbstractPlugin
 */
public abstract class AbstractSelectedRecordItemPlugin extends AbstractPlugin
											           implements RecordItemsPlugin {

    private static final Log LOG = LogFactory.getLog(AbstractSelectedRecordItemPlugin.class);
    
    private RecordItem lastSelectedRecordItem;
    
	public boolean isVisualizationNecessary(RecordItem recordItem) {
		return recordItem.isSelected();
	}

	public void draw() {
	    RecordItem tSelectedRecordItem = getContext().getRecordItemManager().getSelectedRecordItem();
	    if (lastSelectedRecordItem != null && !tSelectedRecordItem.equals(lastSelectedRecordItem)) {
	        if (LOG.isDebugEnabled()) {
	            LOG.debug("Drawing record item: " + tSelectedRecordItem);
	            LOG.debug("Drawn playlist entry is: " + tSelectedRecordItem.getPlaylistEntry());
	        }
	    }
	    lastSelectedRecordItem = tSelectedRecordItem;
	    drawRecordItem(tSelectedRecordItem);
	}

}
